/*
 * @Author: gitee_com_zb
 * @Date: 2024-12-17 15:22:21
 * @LastEditors: gitee_com_zb
 * @LastEditTime: 2024-12-17 15:22:31
 * @FilePath: /algorithm/每日一题14.排序矩阵查找(medium).cpp
 * @Description: 题目链接 https://leetcode.cn/problems/sorted-matrix-search-lcci
 */
class Solution {
public:
    bool searchMatrix(vector<vector<int>>& matrix, int target) {
        if(matrix.size() == 0 || matrix[0].size() == 0) 
            return false;
        int m = matrix.size();
        int n = matrix[0].size();
        int i = 0, j = n - 1;
        while (i < m && j >= 0) {
            if (matrix[i][j] > target) j--;
            else if (matrix[i][j] < target) i++;
            else return true;
        }
        return false;
    }
};
